package com.drunkensaints.android.happyhour;

import java.util.LinkedList;
import java.util.List;

import com.drunkensaints.android.happyhour.data.Location;
import com.drunkensaints.android.happyhour.db.DbManager;
import com.google.android.maps.MapActivity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainScreen extends MapActivity {
	private DbManager dbManager;
	private LinkedList<Location> locations;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		dbManager = new DbManager(getApplicationContext());
		locations = dbManager.getLocationsForStartScreen();
		LocationListAdapter adapter = new LocationListAdapter(getApplicationContext(), R.layout.start_screen_list_row, locations);
		ListView smallListView = (ListView) findViewById(R.id.smallOfferList);
		smallListView.setAdapter(adapter);
	}

	class LocationListAdapter extends ArrayAdapter<Location> {

		private List<Location> items;
		private Context context;

		public LocationListAdapter(Context context, int textViewResourceId,
				List<Location> objects) {
			super(context, textViewResourceId, objects);
			this.items = objects;
			this.context = context;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View rowView;
			if (convertView == null) {
				LayoutInflater inflater = (LayoutInflater) context
						.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				rowView = inflater
						.inflate(R.layout.start_screen_list_row, null, true);
			}
			else {
				rowView = convertView;
			}
			Location tmpLocation = this.items.get(position);
			TextView shortDescription = (TextView) rowView.findViewById(R.id.shortDescript);
			shortDescription.setText(tmpLocation.shortDescription);
			return rowView;
		}

	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}